/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ex.other;

import ex.tableapi.ApiFrame;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.types.Row;

import java.time.LocalDateTime;

/**
 * A unit test of the spend report.
 * If this test passes then the business
 * logic is correct.
 */
public class SpendReportTest extends ApiFrame {
    private static final LocalDateTime DATE_TIME = LocalDateTime.of(2020, 1, 1, 0, 0);
    private String outName = "printOutTable";
    private String createPrintOutDDL = 
            "CREATE TABLE printOutTable (" +
            "  `account_id` BIGINT," +
            "  `amount` BIGINT," +
             "  `transaction_time` TIMESTAMP(3)" +
            ") WITH (" +
            " 'connector' = 'print' " +
            ")";
    public static void main(String[] args) {
        EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build();
        TableEnvironment tEnv = TableEnvironment.create(settings);

        Table transactions =
                tEnv.fromValues(
                        DataTypes.ROW(
                                DataTypes.FIELD("account_id", DataTypes.BIGINT()),
                                DataTypes.FIELD("amount", DataTypes.BIGINT()),
                                DataTypes.FIELD("transaction_time", DataTypes.TIMESTAMP(3))),
                        Row.of(1, 188, DATE_TIME.plusMinutes(12)),
                        Row.of(2, 374, DATE_TIME.plusMinutes(47)),
                        Row.of(3, 112, DATE_TIME.plusMinutes(36)),
                        Row.of(4, 478, DATE_TIME.plusMinutes(3)),
                        Row.of(5, 208, DATE_TIME.plusMinutes(8)),
                        Row.of(1, 379, DATE_TIME.plusMinutes(53)),
                        Row.of(2, 351, DATE_TIME.plusMinutes(32)),
                        Row.of(3, 320, DATE_TIME.plusMinutes(31)),
                        Row.of(4, 259, DATE_TIME.plusMinutes(19)),
                        Row.of(5, 273, DATE_TIME.plusMinutes(42)));

        transactions.printSchema();
        String createInDDL=
                "CREATE TABLE printOutTable (" +
                        "  `account_id` BIGINT," +
                        "  `amount` BIGINT," +
                        "  `transaction_time` TIMESTAMP(3)" +
                        ") WITH (" +
                        " 'connector' = 'print' " +
                        ")";

        tEnv.executeSql(createInDDL);
        transactions.executeInsert("printOutTable");
    }
//+I[2, 374, 2020-01-01T00:47]
//+I[3, 112, 2020-01-01T00:36]
//+I[5, 208, 2020-01-01T00:08]
//+I[1, 379, 2020-01-01T00:53]
//+I[4, 259, 2020-01-01T00:19]
//+I[5, 273, 2020-01-01T00:42]
//+I[1, 188, 2020-01-01T00:12]
//+I[4, 478, 2020-01-01T00:03]
//+I[2, 351, 2020-01-01T00:32]
//+I[3, 320, 2020-01-01T00:31]
}
